[FilterScript] IRC (Internet Relay Chat)

Started by SA:MP, May 10, 2023, 02:54 PM

Previous topic - Next topic

0 Members and 6 Guests are viewing this topic.

DavidThedy

Скачать бесплатные приложения https://apprepository.ru и игры для Андроид. Все программы доступны на русском языке.

DavidThedy

Скачать бесплатные приложения https://apprepository.ru и игры для Андроид. Все программы доступны на русском языке.

DavidThedy

Скачать бесплатные приложения https://apprepository.ru и игры для Андроид. Все программы доступны на русском языке.

Vincentfed

Клуб для беременных https://mam.ck.ua и молодых мам: встречи, советы специалистов, обсуждения важных тем, занятия по уходу за малышом. Поддержка и полезная информация для комфортного материнства.

Vincentfed

Клуб для беременных https://mam.ck.ua и молодых мам: встречи, советы специалистов, обсуждения важных тем, занятия по уходу за малышом. Поддержка и полезная информация для комфортного материнства.

Vincentfed

Клуб для беременных https://mam.ck.ua и молодых мам: встречи, советы специалистов, обсуждения важных тем, занятия по уходу за малышом. Поддержка и полезная информация для комфортного материнства.

Josephmoort

Женский портал https://glamour.kyiv.ua это твой гид по красоте, здоровью, моде и личностному развитию. Здесь ты найдёшь полезные советы, вдохновение и поддержку на пути к гармонии с собой.

Josephmoort

Женский портал https://glamour.kyiv.ua это твой гид по красоте, здоровью, моде и личностному развитию. Здесь ты найдёшь полезные советы, вдохновение и поддержку на пути к гармонии с собой.

Josephmoort

Женский портал https://glamour.kyiv.ua это твой гид по красоте, здоровью, моде и личностному развитию. Здесь ты найдёшь полезные советы, вдохновение и поддержку на пути к гармонии с собой.

SA:MP

[FilterScript] IRC (Internet Relay Chat)



IRC (Internet Relay Chat)



WARNING: If you're someone who don't like to read a lot, you can scroll to the bottom of this thread for the Pastebin link of the Filterscript. Questions concerning the filterscript will be answered in the discord server and in the comments section of this thread!

Introduction

This IRC Filterscript and its simple tutorial was created for both new and old members to the field of San Andreas Multiplayer Development. It can be used for any type of gamemode, especially Roleplay and Freeroam. It's detailed with the steps to guide you on setting up the filterscript, and the functions of each part within it. Before I created this, I've looked through the present filterscripts that relates to the IRC plugin, and majority of them are too plain, while the others are spoon fed to the new developers instead of showing them what goes where, one at a time.



Explanation of the Filterscript's Usage



Step One

First thing's first, you'll have to identify and include the plugins needed for this FS to actually work. Without them, a FS isn't a FS.



With that being said, the includes which we'll be adding are a_samp (mandatory), irc (the backbone), foreach (to send a message to each player with a common player feature), and sscanf (used to split the strings).




HTML Code:

#include <a_samp>
#include <irc>
#include <foreach>
#include <sscanf2>

Step Two

After the includes were identified and added to the top of the script, we'll move on to defining the hostname of the IRC server, the port attached to it, and of course, a channel in your IRC server for messages to be sent to, when things are done in-game.




HTML Code:

#define IRC_MAIN_SERVER "host.name.net"
#define IRC_PORT (1111)
#define IRC_CHANNEL "name"

Step Three

After the IRC hostname and its affiliated resources have been defined, the color which we'll be using for sending Admin messages in-game will be Red, so define it:




HTML Code:

#define COLOR_ADMIN   (0xFF6347FF)

Step Four

The next thing to do is define GroupID and BotAdmin. The GroupID will be used for creating a group within the IRC server, and the BotAdmin will be used to connect your bot to the server after it's creation, and make it an Admin.




HTML Code:

new GroupID, BotAdmin;

Step Five

If you're aware of how SAMP works, you should understand that OnGameModeInit is called when the server starts or restarts, and it is used for changes to be effective, such as mappings within the gamemode, loading data from the SQL database, and what not. This is where BotAdmin becomes beneficial, because it connects to the IRC server, using the IRC_Connect function, hostname from IRC_MAIN_SERVER, port from IRC_PORT, nickname, realname, and username.



NOTE: The "nickname", "realname", and "username" must be changed before you compile this FS.




HTML Code:

public OnGameModeInit()
{
BotAdmin = IRC_Connect(IRC_MAIN_SERVER, IRC_PORT, "nickname", "realname", "username");
IRC_SetIntData(BotAdmin, E_IRC_CONNECT_DELAY, 5);

GroupID = IRC_CreateGroup();
return 1;
}

Step Six

After this, the bot will join the defined IRC channel (IRC_CHANNEL) IF it's an Admin (BotAdmin, as identified above). If it's not an Admin bot (BotAdmin), it won't connect. The bot is then added to the group (GroupID) as well.




HTML Code:

public IRC_OnConnect(botid, ip[], port)
{
if(botid == BotAdmin)
{
IRC_JoinChannel(botid, IRC_CHANNEL, "key");
IRC_AddToGroup(GroupID, botid);
}
return 1;
}

Step Seven

After the IRC channel is disconnected from the SAMP server OR the gamemode stops running, causing the server to stop too, it'll call this function shown below (IRC_OnDisconnect). It basically removes the bot from the group (defined by GroupID)




HTML Code:

public IRC_OnDisconnect(botid, ip[], port, reason[])
{
IRC_RemoveFromGroup(GroupID, botid);
return 1;
}

Step Eight

The next thing you'll want to do is add the IRC_OnConnectAttempt function. As the name says, it's called when the connection is attempted. This basically prints the attempt message to server_log.txt




HTML Code:

public IRC_OnConnectAttempt(botid, ip[], port)
{
printf("AdmWarn: IRC_OnConnectAttempt: Bot ID %d is now attempting to connect to IRC Server with Hostname (IP): %s, attached to port: %d", botid, ip, port);
return 1;
}

Step Nine

This function (IRC_OnConnectAttemptFail) below must be added to print an error message to the server_log.txt file if the IRC connection was attempted and unfortunately failed.




HTML Code:

public IRC_OnConnectAttemptFail(botid, ip[], port, reason[])
{
printf("AdmWarn: IRC_OnConnectAttemptFail: Bot ID %d has failed to connect to IRC server with hostname (IP): %s, attached to port %d. The reason for this is %s", botid, ip, port, reason);
return 1;
}

Step Ten

After the gamemode stops running, and the server stops or shuts down, this common function to SAMP developers (OnGameModeExit) will be called. It will send a message to the channel from the bot, then destroy the group which was created earlier with (GroupID).




HTML Code:

public OnGameModeExit()
{
IRC_Quit(BotAdmin, "AdmWarn: The server has shut down and the gamemode will stop running.");
IRC_DestroyGroup(GroupID);
return 1;
}

Step Eleven

When a player connects (OnPlayerConnect) to the server, it'll send a message to the defined IRC channel (IRC_CHANNEL), notifying others who are viewing the channel at the same time.



NOTE: You'll see the new ReturnName and SendAdminMessage functions from this point onwards, but do not worry because their functions will be provided at the end of this thread.




HTML Code:

public OnPlayerConnect(playerid)
{
new string[128];

format(string, sizeof(string), "AdmWarn: Character %s (ID: %d) joined the server.", ReturnName(playerid), playerid);
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
return 1;
}

Step Twelve

In contrast, if a player disconnects (OnPlayerDisconnect) from the server, this function is commonly called, and as a result, the disconnect message is sent to the IRC channel.




HTML Code:

public OnPlayerDisconnect(playerid, reason)
{
new string[200];

format(string, sizeof(string), "AdmWarn: Character %s (ID: %d) disconnected from the server.", ReturnName(playerid), playerid);
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
return 1;
}

Step Thirteen

The OnPlayerDeath function is called when a player dies, and must be added to your FS afterwards. If a player is killed by another player, it sends a message to both the SAMP and IRC servers. On the other hand, if the player dies naturally, it'll state that.




Code:

public OnPlayerDeath(playerid, killerid, reason)
{
new string[200];
if(killerid != INVALID_PLAYER_ID)
{
format(string, sizeof(string), "AdmWarn: %s (ID: %d) died (Killer: %s ID: %d).", ReturnName(playerid), playerid, ReturnName(killerid), killerid);
SendAdminMessage(COLOR_ADMIN, string);

format(string, sizeof(string), "AdmWarn: %s (ID: %d) died (Killer: %s ID: %d).", ReturnName(playerid), playerid, ReturnName(killerid), killerid);
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
}
else
{
format(string, sizeof(string), "AdmWarn: %s (ID: %d) died.", ReturnName(playerid), playerid);
SendAdminMessage(COLOR_ADMIN, string);

format(string, sizeof(string), "AdmWarn: %s (ID: %d) died.", ReturnName(playerid), playerid);
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
}
return 1;
}

Step Fourteen

Similarly to how a player dies, a vehicle can be destroyed too. When a vehicle is destroyed by a player, their ID and character name can be identified by this function (OnVehicleDeath), and called to send a message.




Code:

public OnVehicleDeath(vehicleid, killerid)
{
new string[200];
format(string, sizeof(string), "AdmWarn: Vehicle ID %d was destroyed by %s.", vehicleid, ReturnName(killerid));
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
return 1;
}

Step Fifteen

Remember those two things which you read about? The ReturnName and SendAdminMessage functions/stocks. Well, here they are:




Code:

stock ReturnName(playerid)
{
new name[90], character[MAX_PLAYER_NAME];
GetPlayerName(playerid, character, sizeof(character));
name = character;
return name;
}

stock SendAdminMessage(color, const str[])
{
foreach(new i : Player)
{
if(IsPlayerAdmin(i))
{
SendClientMessage(i, color, str);
}
}
return 1;
}

ReturnName: This stock gets the actual and FULL name which was used by the player to connect to the server, no matter what the size is (I doubt anyone would use a name which has 20+ characters), and returns it.



NOTE: The underscore can be removed anytime, but I made this tutorial a bit simple.



SendAdminMessage: This checks for all players who are connected to the server and are RCON Admins at the same time, then sends the message to them.



Step Sixteen

The Commands! (Yeap, I added two commands for you, FOR NOW )

One command is used for communicating with RCON admins from IRC to in-game, while the other is used for kicking players from IRC.




Code:

IRCCMD:a(botid, channel[], user[], host[], params[])
{
if (IRC_IsOp(botid, channel, user))
{
    new string[200];
   
if(isnull(params))
{
                        format(string, sizeof(string), "Usage: !a [Admin Message]");
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
}
else
  {
format(string, sizeof(string), "IRC Admin: %s: %s", user, params);
SendAdminMessage(0x6CEFF0FF, string);
}
}
return 1;
}

IRCCMD:kick(botid, channel[], user[], host[], params[])
{
if(IRC_IsOp(botid, channel, user))
{
new playerid, reason[64];

if(sscanf(params, "ds[64]", playerid, reason))
{
IRC_Say(botid, user, "Usage: !kick [playerid] [reason]");
return 1;
}

if(IsPlayerConnected(playerid))
{
new string[128];

format(string, sizeof(string), "AdmCmd: %s was kicked by %s (IRC), Reason: %s", ReturnName(playerid), user, reason);
IRC_GroupSay(GroupID, IRC_CHANNEL, string);
Kick(playerid);
}
}
return 1;
}

Download Links

IRC Include: https://falcon-host.org/uploads/irc.rar

IRC Plugin: https://falcon-host.org/uploads/irc-plugin.rar



sscanf Include: https://falcon-host.org/uploads/sscanf.rar

sscanf Plugin: https://falcon-host.org/uploads/sscanf-plugin.rar



foreach Include: https://falcon-host.org/uploads/foreach.rar



a_samp Include: https://falcon-host.org/uploads/a_samp.rar



YouTube Video of what I just did: https://www.youtube.com/watch?v=jtMGBsTtcVo&t=11s (It's my new YouTube channel, so can you please like the video, subscribe to my channel and comment? Your comment doesn't have to be good, it can be bad or based on criticism. I like to work while criticizing and challenging myself.)



Discord Server for Support: https://discordapp.com/invite/jr5Ywkm https://discord.io/ChaoticTheDev



Pastebin (If you're LAZY and just want the actual thing ) https://pastebin.com/Ap0JXBZh




Source: [FilterScript] IRC (Internet Relay Chat)